package org.fioma.tree.suffixTree.memory;

import org.fioma.tree.SimpleTreeHandler;
import org.fioma.tree.bytes.LabelRefBytesIndex;
import org.fioma.tree.bytes.LabelRefBytesIndexFactory;

public abstract class SimpleSuffixTreeHandlerMemory<I extends InternalSuffixNodeMemory<I, F, N>, F extends LeafSuffixNodeMemory<I, F, N>, N extends SuffixNodeMemory<I, F, N>>
		extends SimpleTreeHandler<LabelRefBytesIndex, I, F, N> implements SuffixTreeHandlerMemory<I, F, N> {

	protected Memory memory;

	LabelRefBytesIndexFactory labelFactory;

	public SimpleSuffixTreeHandlerMemory(Memory memory, LabelRefBytesIndexFactory labelFactory) {
		// super(nodeFactory);
		this.memory = memory;
		this.labelFactory = labelFactory;
	}

	@Override
	public LabelRefBytesIndexFactory getLabelFactory() {
		return labelFactory;
	}

//	@Override
//	public N[] createChildrenNodes() {
//		return new SuffixNodeMemory[4];
//	}
//
	@Override
	public I createInternalNode() {
		long pos = getMemory().allocMemoryInternalNode();
		return createInternalNode(pos);
	}

	@Override
	public F createLeafNode() {
		long pos = memory.allocMemoryLeafNode();
		return createLeafNode(pos);
	}

	@Override
	public Memory getMemory() {
		return memory;
	}

}
